#!/usr/bin/node

const log = console.log,
      fs = require('fs'),
      http = require('http');

http.createServer((req,res)=>{
  log(`${req.method} ${req.url} http/${req.httpVersion}`);

  log('header:',req.headers);
  log(`process pid:${process.pid}`);

  let file = __dirname + req.url;

  if(fs.existsSync(file)){
    fs.createReadStream(file).pipe(res);
  }else{
    res.statusCode = 404;
    res.end('error');
  }

  log(`process.memoryUsage().heapUsed:${process.memoryUsage().heapUsed}`);
}).listen(8080);


